package com.zhaoxi.project.mes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zhaoxi.framework.aspectj.lang.annotation.Log;
import com.zhaoxi.framework.aspectj.lang.enums.BusinessType;
import com.zhaoxi.project.mes.domain.MesProcess;
import com.zhaoxi.project.mes.service.impl.MesProcessServiceImpl;
import com.zhaoxi.framework.web.controller.BaseController;
import com.zhaoxi.framework.web.domain.AjaxResult;
import com.zhaoxi.common.utils.poi.ExcelUtil;
import com.zhaoxi.framework.web.page.TableDataInfo;

/**
 * 工序Controller
 * 
 * @author zhaoxi
 * @date 2023-08-28
 */
@RestController
@RequestMapping("/mes/process")
public class MesProcessController extends BaseController
{
    @Autowired
    private MesProcessServiceImpl mesProcessService;

    /**
     * 查询工序列表
     */
    @PreAuthorize("@ss.hasPermi('mes:process:list')")
    @GetMapping("/list")
    public TableDataInfo list(MesProcess mesProcess)
    {
        startPage();
        List<MesProcess> list = mesProcessService.selectMesProcessList(mesProcess);
        return getDataTable(list);
    }

    /**
     * 导出工序列表
     */
    @PreAuthorize("@ss.hasPermi('mes:process:export')")
    @Log(title = "工序", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesProcess mesProcess)
    {
        List<MesProcess> list = mesProcessService.selectMesProcessList(mesProcess);
        ExcelUtil<MesProcess> util = new ExcelUtil<MesProcess>(MesProcess.class);
        util.exportExcel(response, list, "工序数据");
    }

    /**
     * 获取工序详细信息
     */
    @PreAuthorize("@ss.hasPermi('mes:process:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mesProcessService.selectMesProcessById(id));
    }

    /**
     * 新增工序
     */
    @PreAuthorize("@ss.hasPermi('mes:process:add')")
    @Log(title = "工序", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesProcess mesProcess)
    {
        return toAjax(mesProcessService.insertMesProcess(mesProcess));
    }

    /**
     * 修改工序
     */
    @PreAuthorize("@ss.hasPermi('mes:process:edit')")
    @Log(title = "工序", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesProcess mesProcess)
    {
        return toAjax(mesProcessService.updateMesProcess(mesProcess));
    }

    /**
     * 删除工序
     */
    @PreAuthorize("@ss.hasPermi('mes:process:remove')")
    @Log(title = "工序", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mesProcessService.deleteMesProcessByIds(ids));
    }
}
